package nettyhttpserver;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import io.netty.buffer.ByteBuf;
public class SockerServerHandler extends ChannelInboundHandlerAdapter  {
	  @Override
	    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // (2)
	  //    super.channelRead(ctx, msg);
		  ByteBuf in = (ByteBuf) msg;
	        try {
	            while (in.isReadable()) {
	                System.out.print((char) in.readByte());
	                System.out.flush();
	            }
	        } finally {
	            ReferenceCountUtil.release(msg);
	        }
	    }

	    @Override
	    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { // (5)
//	        super.exceptionCaught(ctx, cause);
	        cause.printStackTrace();
	        ctx.close();
	    }
}
